﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RunningSimulation.frmMain
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.RunningSimulation;

public class frmMain : TxForm
{
  private TxSimulationPlayer m_simulation;
  private SimulationRunner m_runningSimulation;
  private IContainer components;
  private Button btnStart;
  private TextBox txtFileName;
  private Label label1;
  private Button btnStop;
  private Label label2;
  private TextBox txtTimeToRecord;
  private RadioButton rdbRecord;
  private RadioButton rdbCompare;
  private Button btnHelp;
  private Label label3;
  private TextBox txtTime;
  private Panel panel1;
  private Label label4;
  private Button button1;
  private Panel panel2;
  private Label label5;
  private Label label6;
  private NumericUpDown m_toleranceToCompareBtn;

  public frmMain() => this.InitializeComponent();

  private void frmMain_Load(object sender, EventArgs e) => this.btnStop.Enabled = false;

  private void btnStart_Click(object sender, EventArgs e)
  {
    SimulationFileAccessor fileAccessor;
    if (this.rdbRecord.Checked)
      fileAccessor = (SimulationFileAccessor) new SimulationFileWriter();
    else if (this.rdbCompare.Checked)
    {
      fileAccessor = (SimulationFileAccessor) new SimulationFileComparer();
    }
    else
    {
      int num = (int) TxMessageBox.Show("you didn't mention if you would like to record or compare", "Simulation Recorder", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
      return;
    }
    fileAccessor.m_toleranceToCompare = (double) this.m_toleranceToCompareBtn.Value;
    this.m_simulation = TxApplication.ActiveDocument.SimulationPlayer;
    this.m_simulation.TimeIntervalReached += new TxSimulationPlayer_TimeIntervalReachedEventHandler(this.m_simulation_TimeIntervalReached);
    this.m_runningSimulation = new SimulationRunner();
    if (!this.m_runningSimulation.startRecording(this.txtFileName.Text, this.txtTimeToRecord.Text, fileAccessor))
      return;
    this.btnStart.Enabled = false;
    this.btnStop.Enabled = true;
  }

  private void m_simulation_TimeIntervalReached(
    object sender,
    TxSimulationPlayer_TimeIntervalReachedEventArgs args)
  {
    this.txtTime.Text = args.CurrentTime.ToString();
    if (this.m_simulation.CurrentTime <= Convert.ToDouble(this.txtTimeToRecord.Text) || Convert.ToDouble(this.txtTimeToRecord.Text) == 0.0)
      return;
    this.btnStart.Enabled = true;
    this.btnStop.Enabled = false;
  }

  private void btnStop_Click(object sender, EventArgs e)
  {
    this.m_runningSimulation.stopRecording();
    this.m_runningSimulation = (SimulationRunner) null;
    this.m_simulation.TimeIntervalReached -= new TxSimulationPlayer_TimeIntervalReachedEventHandler(this.m_simulation_TimeIntervalReached);
    this.btnStart.Enabled = true;
    this.btnStop.Enabled = false;
  }

  private void btnHelp_Click(object sender, EventArgs e)
  {
    int num = (int) TxMessageBox.Show("For further information, please check out: http://cipgweb/msg_devdoc/dokuwiki/tecno_prog_notes:simulation_recorder_ui", "Simulation Recorder Help", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  }

  private void button1_Click(object sender, EventArgs e) => this.CloseAll();

  private void frmMain_FormClosed(object sender, FormClosedEventArgs e) => this.CloseAll();

  private void CloseAll()
  {
    if (this.m_runningSimulation != null)
      this.m_runningSimulation.stopRecording();
    this.m_runningSimulation = (SimulationRunner) null;
    if (this.m_simulation != null)
      this.m_simulation.TimeIntervalReached -= new TxSimulationPlayer_TimeIntervalReachedEventHandler(this.m_simulation_TimeIntervalReached);
    ((Form) this).Close();
  }

  private void btnStart_EnabledChanged(object sender, EventArgs e)
  {
    bool enabled = this.btnStart.Enabled;
    this.rdbRecord.Enabled = enabled;
    this.rdbCompare.Enabled = enabled;
    this.m_toleranceToCompareBtn.Enabled = enabled;
    this.txtTimeToRecord.Enabled = enabled;
    this.txtFileName.Enabled = enabled;
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    this.btnStart = new Button();
    this.txtFileName = new TextBox();
    this.label1 = new Label();
    this.btnStop = new Button();
    this.label2 = new Label();
    this.txtTimeToRecord = new TextBox();
    this.rdbRecord = new RadioButton();
    this.rdbCompare = new RadioButton();
    this.btnHelp = new Button();
    this.label3 = new Label();
    this.txtTime = new TextBox();
    this.panel1 = new Panel();
    this.m_toleranceToCompareBtn = new NumericUpDown();
    this.label6 = new Label();
    this.label4 = new Label();
    this.button1 = new Button();
    this.panel2 = new Panel();
    this.label5 = new Label();
    this.panel1.SuspendLayout();
    this.m_toleranceToCompareBtn.BeginInit();
    this.panel2.SuspendLayout();
    ((Control) this).SuspendLayout();
    this.btnStart.BackColor = Color.YellowGreen;
    this.btnStart.Font = new Font("Microsoft Sans Serif", 9.75f, FontStyle.Bold, GraphicsUnit.Point, (byte) 0);
    this.btnStart.Location = new Point(19, 235);
    this.btnStart.Name = "btnStart";
    this.btnStart.Size = new Size(160 /*0xA0*/, 57);
    this.btnStart.TabIndex = 0;
    this.btnStart.Text = "Start";
    this.btnStart.UseVisualStyleBackColor = false;
    this.btnStart.EnabledChanged += new EventHandler(this.btnStart_EnabledChanged);
    this.btnStart.Click += new EventHandler(this.btnStart_Click);
    this.txtFileName.Location = new Point(38, 185);
    this.txtFileName.Name = "txtFileName";
    this.txtFileName.Size = new Size(294, 20);
    this.txtFileName.TabIndex = 1;
    this.txtFileName.Text = "c:\\SimulationRecordings\\first.log";
    this.label1.AutoSize = true;
    this.label1.Location = new Point(35, 169);
    this.label1.Name = "label1";
    this.label1.Size = new Size(94, 13);
    this.label1.TabIndex = 2;
    this.label1.Text = "Log File Location: ";
    this.btnStop.BackColor = Color.Pink;
    this.btnStop.Font = new Font("Microsoft Sans Serif", 9.75f, FontStyle.Bold, GraphicsUnit.Point, (byte) 0);
    this.btnStop.Location = new Point(189, 235);
    this.btnStop.Name = "btnStop";
    this.btnStop.Size = new Size(162, 57);
    this.btnStop.TabIndex = 3;
    this.btnStop.Text = "Stop";
    this.btnStop.UseVisualStyleBackColor = false;
    this.btnStop.Click += new EventHandler(this.btnStop_Click);
    this.label2.AutoSize = true;
    this.label2.Location = new Point(35, 142);
    this.label2.Name = "label2";
    this.label2.Size = new Size(248, 13);
    this.label2.TabIndex = 5;
    this.label2.Text = "Record/Compare End Time (0 for entire simulation):";
    this.txtTimeToRecord.Location = new Point(280, 18);
    this.txtTimeToRecord.Name = "txtTimeToRecord";
    this.txtTimeToRecord.Size = new Size(30, 20);
    this.txtTimeToRecord.TabIndex = 4;
    this.txtTimeToRecord.Text = "0";
    this.txtTimeToRecord.TextAlign = HorizontalAlignment.Center;
    this.rdbRecord.AutoSize = true;
    this.rdbRecord.Checked = true;
    this.rdbRecord.Location = new Point(44, 38);
    this.rdbRecord.Name = "rdbRecord";
    this.rdbRecord.Size = new Size(60, 17);
    this.rdbRecord.TabIndex = 6;
    this.rdbRecord.TabStop = true;
    this.rdbRecord.Text = "Record";
    this.rdbRecord.UseVisualStyleBackColor = true;
    this.rdbCompare.AutoSize = true;
    this.rdbCompare.Location = new Point(44, 61);
    this.rdbCompare.Name = "rdbCompare";
    this.rdbCompare.Size = new Size(67, 17);
    this.rdbCompare.TabIndex = 7;
    this.rdbCompare.Text = "Compare";
    this.rdbCompare.UseVisualStyleBackColor = true;
    this.btnHelp.BackColor = Color.FromArgb(224 /*0xE0*/, 224 /*0xE0*/, 224 /*0xE0*/);
    this.btnHelp.Location = new Point(21, 377);
    this.btnHelp.Name = "btnHelp";
    this.btnHelp.Size = new Size(72, 23);
    this.btnHelp.TabIndex = 8;
    this.btnHelp.Text = "Help";
    this.btnHelp.UseVisualStyleBackColor = false;
    this.btnHelp.Click += new EventHandler(this.btnHelp_Click);
    this.label3.AutoSize = true;
    this.label3.Font = new Font("Microsoft Sans Serif", 11.25f, FontStyle.Regular, GraphicsUnit.Point, (byte) 0);
    this.label3.Location = new Point(18, 322);
    this.label3.Name = "label3";
    this.label3.Size = new Size(189, 18);
    this.label3.TabIndex = 9;
    this.label3.Text = "Recording/Comparing now:";
    this.txtTime.BackColor = Color.FromArgb(224 /*0xE0*/, 224 /*0xE0*/, 224 /*0xE0*/);
    this.txtTime.Enabled = false;
    this.txtTime.Font = new Font("Microsoft Sans Serif", 18f, FontStyle.Regular, GraphicsUnit.Point, (byte) 0);
    this.txtTime.Location = new Point(218, 315);
    this.txtTime.Name = "txtTime";
    this.txtTime.Size = new Size(94, 35);
    this.txtTime.TabIndex = 10;
    this.txtTime.Text = "0";
    this.txtTime.TextAlign = HorizontalAlignment.Center;
    this.panel1.AccessibleDescription = "sdfgsdf";
    this.panel1.AccessibleName = "sdfsdfsdf";
    this.panel1.BorderStyle = BorderStyle.FixedSingle;
    this.panel1.Controls.Add((Control) this.m_toleranceToCompareBtn);
    this.panel1.Controls.Add((Control) this.label6);
    this.panel1.Location = new Point(21, 24);
    this.panel1.Name = "panel1";
    this.panel1.Size = new Size(330, 70);
    this.panel1.TabIndex = 11;
    this.m_toleranceToCompareBtn.DecimalPlaces = 2;
    this.m_toleranceToCompareBtn.Location = new Point(280, 30);
    this.m_toleranceToCompareBtn.Name = "m_toleranceToCompareBtn";
    this.m_toleranceToCompareBtn.Size = new Size(45, 20);
    this.m_toleranceToCompareBtn.TabIndex = 11;
    this.m_toleranceToCompareBtn.Value = new Decimal(new int[4]
    {
      5,
      0,
      0,
      65536 /*0x010000*/
    });
    this.label6.AutoSize = true;
    this.label6.Font = new Font("Microsoft Sans Serif", 8.25f);
    this.label6.Location = new Point(146, 38);
    this.label6.Name = "label6";
    this.label6.Size = new Size(115, 13);
    this.label6.TabIndex = 10;
    this.label6.Text = "Tolerance to Compare:";
    this.label4.AutoSize = true;
    this.label4.Location = new Point(32 /*0x20*/, 16 /*0x10*/);
    this.label4.Name = "label4";
    this.label4.Size = new Size(135, 13);
    this.label4.TabIndex = 12;
    this.label4.Text = "Select Record or Compare:";
    this.button1.BackColor = Color.FromArgb(224 /*0xE0*/, 224 /*0xE0*/, 224 /*0xE0*/);
    this.button1.Location = new Point(276, 377);
    this.button1.Name = "button1";
    this.button1.Size = new Size(75, 23);
    this.button1.TabIndex = 13;
    this.button1.Text = "Close";
    this.button1.UseVisualStyleBackColor = false;
    this.button1.Click += new EventHandler(this.button1_Click);
    this.panel2.AccessibleDescription = "sdfgsdf";
    this.panel2.AccessibleName = "sdfsdfsdf";
    this.panel2.BorderStyle = BorderStyle.FixedSingle;
    this.panel2.Controls.Add((Control) this.txtTimeToRecord);
    this.panel2.Location = new Point(21, 120);
    this.panel2.Name = "panel2";
    this.panel2.Size = new Size(330, 96 /*0x60*/);
    this.panel2.TabIndex = 12;
    this.label5.AutoSize = true;
    this.label5.Location = new Point(32 /*0x20*/, 113);
    this.label5.Name = "label5";
    this.label5.Size = new Size(133, 13);
    this.label5.TabIndex = 15;
    this.label5.Text = "Record/Compare Settings:";
    ((ContainerControl) this).AutoScaleDimensions = new SizeF(6f, 13f);
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Control) this).BackColor = Color.White;
    ((Control) this).BackgroundImageLayout = ImageLayout.None;
    ((Form) this).ClientSize = new Size(370, 412);
    ((Control) this).Controls.Add((Control) this.label5);
    ((Control) this).Controls.Add((Control) this.button1);
    ((Control) this).Controls.Add((Control) this.label4);
    ((Control) this).Controls.Add((Control) this.txtTime);
    ((Control) this).Controls.Add((Control) this.label3);
    ((Control) this).Controls.Add((Control) this.btnHelp);
    ((Control) this).Controls.Add((Control) this.rdbCompare);
    ((Control) this).Controls.Add((Control) this.rdbRecord);
    ((Control) this).Controls.Add((Control) this.label2);
    ((Control) this).Controls.Add((Control) this.btnStop);
    ((Control) this).Controls.Add((Control) this.label1);
    ((Control) this).Controls.Add((Control) this.txtFileName);
    ((Control) this).Controls.Add((Control) this.btnStart);
    ((Control) this).Controls.Add((Control) this.panel1);
    ((Control) this).Controls.Add((Control) this.panel2);
    ((Control) this).Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, (byte) 0);
    ((Control) this).ForeColor = Color.Blue;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (frmMain);
    this.ShouldCloseOnDocumentUnloading = true;
    ((Form) this).ShowIcon = false;
    ((Control) this).Text = "Simulation Recorder - 2.1 ";
    ((Form) this).TopMost = true;
    ((Form) this).FormClosed += new FormClosedEventHandler(this.frmMain_FormClosed);
    ((Form) this).Load += new EventHandler(this.frmMain_Load);
    this.panel1.ResumeLayout(false);
    this.panel1.PerformLayout();
    this.m_toleranceToCompareBtn.EndInit();
    this.panel2.ResumeLayout(false);
    this.panel2.PerformLayout();
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }
}
